/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef DRIVER_TABLE_ABI_H
#define DRIVER_TABLE_ABI_H

#include <stdint.h>

#ifdef __cplusplus
typedef struct device_driver device_driver_t;
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef enum status {
    STATUS_OK              = 0,
    STATUS_ERROR           = 1,
    STATUS_NOT_FOUND       = 2,
    STATUS_INVALID_ARG     = 3,
    STATUS_NOT_IMPLEMENTED = 4,
    STATUS_TIMEOUT         = 5,
    STATUS_BUSY            = 6,
    STATUS_NO_MEMORY       = 7,
} status_t;

typedef void* driver_handle_t; // each device object has one driver instance;
typedef void* device_config_t; // CSR based data object in share memory;

// 定义驱动创建函数类型
typedef driver_handle_t (*driver_ctor)(void* service, const char* object_name);
typedef status_t (*driver_init)(driver_handle_t, void* csr_object, void* connector);
typedef status_t (*driver_start)(driver_handle_t);
typedef status_t (*driver_stop)(driver_handle_t);

typedef const char* (*driver_dump)(driver_handle_t device);

typedef status_t (*register_device_driver_func)(device_driver_t** device_driver, uint8_t* count);
status_t register_device_driver(device_driver_t** device_driver, uint8_t* count);

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
struct device_driver {
    const char*        device_name;    // 设备名称
    const driver_ctor  ctor;           // 创建函数
    const driver_init  init;           // 初始化函数
    const driver_start start;          // 启动函数
    const driver_stop  stop;           // 停止函数
    driver_dump        dump = nullptr; // dump函数
};
#else
struct device_driver {
    const char*        device_name;
    const driver_ctor  ctor;
    const driver_init  init;
    const driver_start start;
    const driver_stop  stop;
    driver_dump        dump;
} device_driver_t;
#endif

#endif //